package com.shengdong.water.feature.web

import android.annotation.SuppressLint
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import com.alibaba.android.arouter.facade.annotation.Route
import com.shengdong.water.R
import com.shengdong.water.code.base.BaseActivity
import com.shengdong.water.code.config.RouterConfig
import com.shengdong.water.databinding.ActivityWebBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = RouterConfig.WEB_PATH)
@AndroidEntryPoint
class WebActivity : BaseActivity<ActivityWebBinding>() {
    override fun getLayoutId() = R.layout.activity_web

    private var webUrl: String? = null
    @SuppressLint("SetJavaScriptEnabled")
    override fun setupView() {
        webUrl = intent.getStringExtra("webUrl")
        val webView = binding.webView
        WebView.setWebContentsDebuggingEnabled(true)
        val webSettings = webView.settings
        webSettings.javaScriptEnabled =true
        webSettings.domStorageEnabled = true
        webSettings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
        webView.webViewClient = object : WebViewClient() {
            override fun onPageFinished(view: WebView?, url: String?) {
                super.onPageFinished(view, url)
                //页面加载完成
                setTitle(view?.title ?: "标题")
            }
        }
        webView.loadUrl(webUrl?:"")

    }
}